package com.zzj.controller;


import com.github.pagehelper.PageInfo;
import com.zzj.bean.LoginHistory;
import com.zzj.service.LoginHistoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

/**
 * <p>
 * InnoDB free: 8192 kB 前端控制器
 * </p>
 *
 * @author 花
 * @since 2022-03-04
 */
@RestController
@RequestMapping("/history")
@Api
@CrossOrigin
public class LoginHistoryController {

    @Autowired
    private LoginHistoryService loginHistoryService;

    @GetMapping("/getAllHistory")
    @ApiOperation("获取所有的登录信息")
    public PageInfo<LoginHistory> getAllHistory(
            @RequestParam(required = false,defaultValue = "1") int pageNum,
            @RequestParam(required = false,defaultValue = "5") int pageSize){
        return loginHistoryService.getAllHistory(pageNum,pageSize);
    }

    @GetMapping("/getHistory")
    @ApiOperation("获取登录信息")
    public PageInfo<LoginHistory> getHistory(
            @RequestParam(required = false,defaultValue = "1") int pageNum,
            @RequestParam(required = false,defaultValue = "5") int pageSize){
        return loginHistoryService.getHistory(pageNum,pageSize);
    }

    @DeleteMapping("delHistory")
    @ApiOperation("删除一条记录")
    public boolean delHistory(String lhid){
        System.out.println("lhid = " + lhid);
        LoginHistory history = loginHistoryService.getById(lhid);
        if (history.getLhstatus().equals("1")){
            history.setLhstatus("0");
        }else {
            history.setLhstatus("1");
        }
        return loginHistoryService.updateById(history);
    }

    @DeleteMapping("delBatHistory")
    @ApiOperation("删除批量记录")
    public boolean delBatHistory(String[] ids){
        List<String> ids1 = Arrays.asList(ids);
        return loginHistoryService.removeByIds(ids1);
    }



}

